﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Winfrom_Login_Test_0001
{
    public class DsHelper
    {

        private static readonly string conString = "server=.;database = Admin001;uid = sa;pwd = cultural0725.";

        //获得表数据，select语句 
        public static DataTable GetDataTable(string sql)
        {          
            SqlConnection sqlConnection = new SqlConnection(conString);

            SqlCommand command = new SqlCommand(sql,sqlConnection);

            SqlDataAdapter dataAdapter = new SqlDataAdapter();

            DataTable table = new DataTable();

            dataAdapter.SelectCommand = command;

            dataAdapter.Fill(table);

            sqlConnection.Open();

            return table;
        }

        //添加、更新、删除  封装
        public static int AddorUpdateorDel(string sql)
        {          

            SqlConnection sqlConnection = new SqlConnection(conString);

            SqlCommand command = new SqlCommand(sql, sqlConnection);

            sqlConnection.Open();

            return command.ExecuteNonQuery();

        }

    }
}
